package hai.com.android_test.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import hai.com.android_test.R;

/**
 * Created by 黄海 on 2016/11/21.
 */

public class RecycleViewActivity extends AppCompatActivity {
    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    List<String> list;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.recycleview);
        ButterKnife.bind(this);
        initData();
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        recycleView.setAdapter(new MyAdapter());
    }

    private void initData() {
        list = new ArrayList();
        for (int i = 0; i < 20; i++) {
            list.add("str:" + i);
        }
    }

    class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {

        @Override
        public MyAdapter.MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//            return new MyHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycleview,parent,false));
            return null;
        }

        @Override
        public void onBindViewHolder(MyAdapter.MyHolder holder, int position) {
            holder.tv.setText(list.get(position));
        }

        @Override
        public int getItemCount() {
            return list.size();
        }

        class MyHolder extends RecyclerView.ViewHolder {
            TextView tv;

            public MyHolder(View itemView) {
                super(itemView);
//                tv= (TextView) itemView.findViewById(R.id.id_num);
            }
        }
    }
}
